package com.sdhs.listmanage.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.sdhs.listmanage.domain.entity.GcManageList;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ManageTreeSelect树结构实体类
 * 
 * @author ww
 */
@Setter
@Getter
public class ManageTreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /** 节点名称 */
    private String label;

    /** 详细数据 */
    private GcManageList data;

    /** 节点禁用 */
    private boolean disabled = false;

    /** 节点变更表示：add-新增，update-修改，delete-删除 */
    private String changeType;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<ManageTreeSelect> children;

    public ManageTreeSelect()
    {}

    public ManageTreeSelect(GcManageList manage)
    {
        this.id = manage.getId();
        this.label = manage.getSubheadingsName();
        this.changeType = manage.getChangeType();
        if("delete".equals(this.changeType) || "add".equals(this.changeType)){
            this.disabled = true;
        }
        this.data = manage;
        this.children = manage.getChildren().stream().map(ManageTreeSelect::new).collect(Collectors.toList());
    }

}
